package me.goldze.mvvmhabit.binding.viewadapter.image;


import android.text.TextUtils;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import me.goldze.mvvmhabit.R;

/**
 * Created by goldze on 2017/6/18.
 */
public final class ViewAdapter {
    @BindingAdapter(value = {"url", "placeholderRes", "isCircle"}, requireAll = false)
    public static void setImageUri(ImageView imageView, String url, int placeholderRes, boolean isCircle) {
//        if (!TextUtils.isEmpty(url)) {
            RequestOptions requestOptions;
            if (isCircle) {
                requestOptions = RequestOptions.bitmapTransform(new CircleCrop());
            } else {
                requestOptions = new RequestOptions();
            }
            requestOptions.placeholder(placeholderRes);
            //使用Glide框架加载图片
            Glide.with(imageView.getContext())
                    .load(url)
                    .apply(requestOptions)
                    .into(imageView);
//        }
    }
}

